//
//  XMTabBarViewController.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/2.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "XMTabBarViewController.h"
#import "HomeViewController.h"
#import "NewsFlashViewController.h"
#import "MarketViewController.h"
#import "MineViewController.h"

@interface XMTabBarViewController ()

@end

@implementation XMTabBarViewController
- (BOOL)shouldAutorotate {
    return NO;
}

/*
-(BOOL)shouldAutorotate{
    RTRootNavigationController *nav = (RTRootNavigationController *)self.selectedViewController;
    if ([nav.rt_topViewController isKindOfClass:[NSClassFromString(@"NewsDetailViewController") class]]) {
        return YES;
    }
    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    RTRootNavigationController *nav = (RTRootNavigationController *)self.selectedViewController;
    if ([nav.rt_topViewController isKindOfClass:[NSClassFromString(@"NewsDetailViewController") class]]) {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    RTRootNavigationController *nav = (RTRootNavigationController *)self.selectedViewController;
    if ([nav.rt_topViewController isKindOfClass:[NSClassFromString(@"NewsDetailViewController") class]]) {
        return UIInterfaceOrientationPortrait|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight;
    }
    return UIInterfaceOrientationPortrait;
    
}
 */

- (void)viewDidLoad {
    [super viewDidLoad];

    HomeViewController * homeVC = [[HomeViewController alloc]init];
    NewsFlashViewController * newsVC = [[NewsFlashViewController alloc]init];
    MarketViewController * marketVC = [[MarketViewController alloc]init];
    MineViewController * mineVC = [[MineViewController alloc]init];
    
    
    [self addChildVc:homeVC tag:0 title:@"首页" image:@"tabbar_home" selectedImage:@"tabbar_home_selected"];
    [self addChildVc:newsVC tag:1 title:@"快讯" image:@"tabbar_kuaixun" selectedImage:@"tabbar_kuaixun_selected"];
    [self addChildVc:marketVC tag:2 title:@"行情" image:@"tabbar_hangqing" selectedImage:@"tabbar_hangqing_selected"];
    [self addChildVc:mineVC tag:3 title:@"评级" image:@"tabbar_pingji" selectedImage:@"tabbar_pingji_selected"];
    
}

- (void)addChildVc:(UIViewController *)childVc tag:(NSInteger)tag title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    // 设置子控制器的文字
    childVc.title = title; // 同时设置tabbar和navigationBar的文字
    // 设置子控制器的图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
//    textAttrs[NSForegroundColorAttributeName] = XMColor(123, 123, 123);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
//    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor xm_MainColor];
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    // 先给外面传进来的小控制器 包装 一个导航控制器
    RTRootNavigationController *nav = [[RTRootNavigationController alloc] initWithRootViewController:childVc];
    // 添加为子控制器
    nav.title = title;
    [self addChildViewController:nav];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
